import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, Validate } from 'class-validator';
import { IsNotExist } from '../../utils/validators/is-not-exists.validator';

export class CreatePermissionDto {
	@ApiProperty({
		example: '添加菜单',
		required: true,
		description: '权限名称',
	})
	@Validate(IsNotExist, ['Permission'], {
		message: '该权限名称已存在',
	})
	@IsNotEmpty()
	name: string;

	@ApiProperty({
		example: 'menu:add',
		required: true,
		description: '授权标识',
	})
	@Validate(IsNotExist, ['Permission'], {
		message: '该授权标识名称已存在',
	})
	@IsNotEmpty()
	resource: string;

	@ApiProperty({
		required: false,
		description: '权限说明',
	})
	@IsOptional()
	description: string;

	@ApiProperty({
		required: false,
		description: '父级权限',
	})
	@IsOptional()
	parentId: number;
}
